package database

import (
	"errors"
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"zk1-project/pkg/global"
	"zk1-project/srv/internal/model/po"
)

func InitMysql() {
	var err error
	mysqlConf := &global.Apps.Server.Mysql
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", mysqlConf.Username, mysqlConf.Password, mysqlConf.Host, mysqlConf.Port, mysqlConf.Database)
	global.DB, err = gorm.Open(mysql.Open(dsn))
	if err != nil {
		panic(errors.New("mysql数据库连接失败"))

	}
	fmt.Println("mysql数据库连接成功")
	global.DB.AutoMigrate(new(po.Exam))
}
